﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="list-content-mail.aspx.cs" Inherits="famails.BackEnd.page.list_content_mail"  MasterPageFile="~/Master.Master"%>


<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div style="width:100%;padding:10px;">
        <!--start content 01-->
        <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="padding:0px;border:1px solid #333;">
            <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="padding:10px 20px;background:#000;color:#fff;font-size:18px;font-weight:bold;position:relative;">   
                Danh sách nội dung
            </div> 
			    
			    <div class="content-module-main">
		          <asp:Panel Visible="false" ID="pnError" runat="server">
                    <div class="error-box round">
                        <asp:Label ID="lblError"  runat="server" Text=""></asp:Label> 
                    </div>
                  </asp:Panel>
                  <asp:Panel Visible="false" ID="pnSuccess" runat="server">
                    <div class="confirmation-box round">
                        <asp:Label ID="lblSuccess"  runat="server" Text=""></asp:Label> 
                    </div>
                  </asp:Panel>
                </div>
        <style>
                    #contentjqxgrid {
                        width:100% !important;
                    }
                    #pagerjqxgrid {
                        width:100% !important;
                    }
                    #contentjqxgrid_error{
                        width:100% !important;
                    }
                    #pagerjqxgrid_error{
                        width:100% !important;
                    }
        </style>
                <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="padding:0px;">
                <div id='jqxWidget' style="width:100%;font-size: 13px; font-family: Verdana; float: left;">
                        <div id="jqxgrid" style="width:100% !important;">
                        </div>
                        <div id="paginginfo">
                        </div>
                    <div id="popupWindow">
                        <div>
                            Xóa nội dung email!
                        </div>
                        <div style="overflow: hidden;">
                            <p>
                                Bạn có chắc là muốn xóa nội dung này không?
                            </p>
                            <button id="del">
                                Yes</button>
                            <button id="cancel">
                                No</button>
                        </div>
                    </div>
                </div>
                </div>
                <%--<form  runat="server">--%>
                <table hidden>
                    <asp:DataList ID="dtlContentMail" runat="server">
                        <HeaderTemplate>

                            <thead>
                                <tr style="font-size: 0.8em;">

                                    <th style="width: 200px;">Ngày tạo</th>
                                    <th>Tiêu đề</th>
                                    <th>Loại nội dung</th>
                                    <th style="width: 150px;">Chức năng</th>
                                </tr>
                            </thead>

                        </HeaderTemplate>
                        <ItemTemplate>

                            <tbody>
                                <tr>

                                    <td>
                                        <asp:ImageButton ID="ImageButton1" runat="server"
                                            ImageUrl="../resource/images/menu-dark-indicator.png" />
                                        <asp:Label ID="lblCreateDate" runat="server"
                                            Text='<%# Eval("CreateDate") %>'></asp:Label>
                                    </td>
                                    <td>
                                        <asp:Label ID="lblSubject" runat="server" Text='<%# Eval("Subject") %>'></asp:Label></td>
                                    
                                    <td>
                                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("ContentType")+""=="1"?"AutoResponder":"Broadcasting" %>'></asp:Label></td>
                                    <td style="width: 150px;">
                                        <asp:ImageButton ID="btnPreview" runat="server"
                                            ImageUrl="../resource/images/Preview-icon.png"
                                            ToolTip="Bạn click vào đây để xem trước nội dung thư với các trình duyệt mail"
                                            OnClick="btnPreview_Click" CommandArgument='<%# Eval("Id") %>' />


                                        <asp:ImageButton ID="btnEdit" runat="server"
                                            ImageUrl="../resource/images/edit-validated-icon.png"
                                            PostBackUrl='<%#"~/backend/page/CreateContentMail.aspx?id=" + Eval("Id")%>' ToolTip="Click để sửa chữa nội dung mail" />

                                        <asp:ImageButton ID="btnSend" runat="server"
                                            ImageUrl="../resource/images/Status-mail-unread-new-icon.png" CommandArgument='<%# Eval("Id") %>'
                                            PostBackUrl='<%# "~/backend/page/send-register.aspx?SendContenID=" + Eval("Id") %>' ToolTip="Click vào đây để lựa chọn nội dung gửi!" />
                                       
                                    </td>

                                </tr>
                            </tbody>



                        </ItemTemplate>
                        <FooterTemplate>
                            <tfoot>
                                <tr>
                                    <td colspan="5" class="table-footer"></td>
                                </tr>
                            </tfoot>

                        </FooterTemplate>
                    </asp:DataList>
                </table>
                <%-- </form>--%>
            </div>
            <!-- end content-module-main -->
                            <script type="text/javascript">
                               
                                jQuery(function ($) {
                                    //alert(id);
                                    var cellsrenderer = function (row, column, value) {
                                        var id = $("#jqxgrid").jqxGrid('getcellvalue', row, "Id");
                                        //alert(name);
                                        return '<a style="margin: 4px;color:#000;" href="CreateContentMail.aspx?id=' + id + '">Chỉnh sửa</a>';
                                    }
                                    var cellsTypeRenderer = function (row, column, value) {
                                        var type = $("#jqxgrid").jqxGrid('getcellvalue', row, "ContentType");
                                        return type == 1 ? "<span style='margin:4px'>Autoresponder</span>" : "<span style='margin:4px'>Broadcast</span>";
                                    }
                                    var cellsPreviewRenderer = function (row, column, value) {
                                        var id = $("#jqxgrid").jqxGrid('getcellvalue', row, "Id");
                                        return '<a style="margin: 4px" href="CreateContentMail.aspx?id=' + id + '">' + value + '</a>';
                                    }
                                    var cellsSendRenderer = function (row, column, value) {
                                        var id = $("#jqxgrid").jqxGrid('getcellvalue', row, "Id");
                                        return '<a style="margin: 4px; text-align: center" href="send-register.aspx?SendContenID=' + id + '"><span style="padding-top:2px;font-size:20px;color:#000;" class="fa fa-envelope-o"></span></a>';
                                    }
                                    $("#jqxgrid").jqxGrid('showloadelement');
                                    $.ajax({
                                        type: "POST",
                                        url: "list-content-mail.aspx/search",
                                        contentType: "application/json; charset=utf-8",
                                        dataType: "json",
                                        success: function (data) {
                                            var source =
                                    {
                                        datatype: "json",
                                        datafields: [
                                            { name: 'Id', type: 'int' },
                                            { name: 'ContentType', type: 'int' },
                                            { name: 'Subject', type: 'string' }
                                        ],
                                        id: 'Id',
                                        localdata: data,
                                        pager: function (pagenum, pagesize, oldpagenum) {
                                        }
                                    };
                                            var dataAdapter = new $.jqx.dataAdapter(source);
                                            $("#jqxgrid").jqxGrid(
                                            {
                                                width: $('#jqxWidget').width(),
                                                source: dataAdapter,
                                                selectionmode: 'multiplerowsextended',
                                                sortable: true,
                                                pageable: true,

                                                autoheight: true,
                                                enabletooltips: true,
                                                columnsresize: true,
                                                pagermode: 'simple',
                                                columns: [
                                                  { text: ' Danh sách nội dung', datafield: 'Subject'},
                                                  {
                                                      text: ' Loại nội dung', datafield: 'ContentType', cellsrenderer: cellsTypeRenderer
                                                  },
                                                  {
                                                      text: 'Xem nội dung', width: 120, cellsrenderer: cellsrenderer
                                                  },
                                                  {
                                                      text: ' Gửi email', datafield: 'Id', width:100,cellsrenderer: cellsSendRenderer
                                                  },
                                                  {
                                                      text: 'Xóa', datafield: 'Delete', columntype: 'button', cellsrenderer: function () {
                                                          return "Xóa";
                                                      }, buttonclick: function (row) {
                                                          // open the popup window when the user clicks a button.
                                                          id = $("#jqxgrid").jqxGrid('getrowid', row);
                                                          var offset = $("#jqxgrid").offset();
                                                          $("#popupWindow").jqxWindow({ position: { x: parseInt(offset.left) + 60, y: parseInt(offset.top) + 60 } });
                                                          // show the popup window.
                                                          $("#popupWindow").jqxWindow('show');
                                                      }
                                                  }
                                                ]
                                            });
                                        }
                                    });
                                });
                                $("#popupWindow").jqxWindow({ width: 250, resizable: false, theme: theme, isModal: true, autoOpen: false, cancelButton: $("#Cancel"), modalOpacity: 0.01 });
                                $("#del").jqxButton({ theme: theme });
                                $("#cancel").jqxButton({ theme: theme });
                                $("#del").click(function () {
                                    //alert(id);
                                    $.ajax({
                                        type: "POST",
                                        url: "list-content-mail.aspx/Delete",
                                        data: "{id:" + id + "}",
                                        contentType: "application/json; charset=utf-8",
                                        dataType: "json",
                                        success: function (data) {
                                            $('#jqxgrid').jqxGrid('deleterow', id);
                                            $("#popupWindow").jqxWindow('hide');
                                        },
                                        error: function (request, status, error) {
                                            alert('Chữ ký đã được gửi. Bạn không được phép xóa!');
                                            $("#popupWindow").jqxWindow('hide');
                                        }
                                    });
                                });
                                $("#cancel").click(function () {
                                    $("#popupWindow").jqxWindow('hide');
                                });
                </script>

    </div>
</asp:Content>

